package main

func diagonalSum(mat [][]int) int {
	cx := -1
	cy := -1
	length := len(mat)
	if length%2 != 0 {
		cx = length / 2
		cy = length / 2
	}
	res := 0
	x := 0
	y := 0
	for x < length && y < length {
		res += mat[x][y]
		x++
		y++
	}
	x = length - 1
	y = 0
	for x >= 0 && y < length {
		if cx != x || cy != y {
			res += mat[x][y]
		}
		x--
		y++
	}

	return res
}
